from notebook.auth import passwd

def getopt():
    import argparse

    parser = argparse.ArgumentParser("Jupyter_passwd_creator", description="")
    parser.add_argument("passwd", action="store", help="生成sha1密码，填入内容")
    parser.add_argument("-j", "--json", action="store", help="生成json配置文件: jupyter notebook password")
    return parser.parse_args()

args = getopt()
if args.json:
    print(">>> 请手动执行：jupyter notebook password")
else:
    sha1 = passwd(args.passwd, 'sha1')
    print(f"[+] 获取到sha1密码，请将以下语句复制到 `~/.jupyter/jupyter_notebook_config.py` 配置中：\nc.NotebookApp.password = u\'{sha1}\'")
